#ifndef XSVFEXEC_XSVF_H_
#define XSVFEXEC_XSVF_H_

/*
 * Copyright (C) 2004-2007 by egnite Software GmbH
 * Copyright (C) 2008 by egnite GmbH
 *
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. Neither the name of the copyright holders nor the names of
 *    contributors may be used to endorse or promote products derived
 *    from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
 * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 * For additional information see http://www.ethernut.de/
 * and Xilinx Application Note XAPP058.
 */

/*
 * $Log$
 * Revision 1.1  2008/10/20 13:10:05  haraldkipp
 * Checked in.
 *
 */

/*!
 * \file xsvf.h
 * \brief TAP state header file.
 */

/*!
 * \addtogroup xgXEDefs
 */
/*@{*/

/*!
 * \brief Maximum number of bytes required to store bit strings.
 *
 * A value of five is sufficient for up to six devices in a chain.
 */
#ifdef ETHERNUT3
#define MAX_BITVEC_BYTES    12
#else
#define MAX_BITVEC_BYTES    5
#endif

/*!
 * \brief Default repeat.
 *
 * Number of times that TDO is tested against the expected value before 
 * the operation is considered a failure.
 */
#define DEFAULT_REPEAT      32

/*@}*/

/*!
 * \addtogroup xgXsvfExec
 */
/*@{*/

/*
 * XSVF error codes.
 */

/*! Error code. Unknown error. */
#define XE_UNKNOWN        1

/*! Error code. Captured TDO value differs from expected TDO value. */
#define XE_TDOMISMATCH    2

/*! Error code. XSVF buffer contains illegal command. */
#define XE_ILLEGALCMD     4

/*! Error code. XSVF buffer contains illegal TAP state. */
#define XE_ILLEGALSTATE   5

/*! Error code. Bit string overflow. */
#define XE_DATAOVERFLOW   6

/*! Error code. End of XSVF data reached without XCOMPLETE. */
#define XE_DATAUNDERFLOW  7

/*
 * XSVF instruction codes.
 */

/*! XSVF command code. End of XSVF buffer. */
#define XCOMPLETE       0x00

/*! XSVF command code. Set the TDO mask. Length has been specified by the last XSDRSIZE command. */
#define XTDOMASK        0x01

/*! XSVF command code. Go to the Shift-IR state and shift in the TDI value. XSIR uses
    a single byte for the TDI size. */
#define XSIR            0x02

/*! 
 * XSVF command code. Go to the Shift-DR state and shift in the TDI value; compare the expected 
 * value from the last XSDRTDO command against the TDO value that was 
 * shifted out. Use the TDO mask which was generated by the last XTDOMASK 
 * instruction.
 */
#define XSDR            0x03

/*! 
 * XSVF command code. Set the number of microseconds the device should stay in the Run-Test-Idle 
 * state after each visit to the SDR state.
 */
#define XRUNTEST        0x04

/*! 
 * XSVF command code. Set the number of times that TDO is tested against the expected value before 
 * the programming operation is considered a failure.
 */
#define XREPEAT         0x07

/*! XSVF command code. Set the length of the next XSDR/XSDRTDO records that follow. */
#define XSDRSIZE        0x08

/*! 
 * XSVF command code. Go to the Shift-DR state and shift in the TDI value; compare the expected
 * value against the TDO value that was shifted out. Use the TDO mask which 
 * was generated by the last XTDOMASK command.
 *
 * The expected TDO value is re-used in successive XSDR commands.
 */
#define XSDRTDO         0x09

/*! XSVF command code. Set SDR address and data masks for interatin XSDR commands. */
#define XSETSDRMASKS    0x0A

/*! Do iterating XSDR commands. */
#define XSDRINC         0x0B

/*! 
 * XSVF command code. Go to the Shift-DR state and shift in the TDI value. No comparison of TDO 
 * value with the last specified expected value is performed.
 */
#define XSDRB           0x0C

/*! 
 * XSVF command code. Continue to stay in Shift-DR state and shift in the TDI value. No comparison 
 * of TDO value with the last specified expected value is performed.
 */
#define XSDRC           0x0D

/*! 
 * XSVF command code. Continue to stay in Shift-DR state and shift in the TDI value. At the end 
 * of the operation, go to the state specified in the last XENDDR command. No
 * comparison of TDO value with the last specified expected value is performed.
 */
#define XSDRE           0x0E

/*! 
 * XSVF command code. Go to the Shift-DR state and shift in the TDI value. Compare all bits of the 
 * expected value against the TDO value that is shifted out. No retries are
 * performed.
 */
#define XSDRTDOB        0x0F

/*! 
 * XSVF command code. Continue to stay in Shift-DR state and shift in the TDI value. Compare all 
 * bits of the expected value against the TDO value that is shifted out.
 */
#define XSDRTDOC        0x10

/*! 
 * XSVF command code. Continue to stay in Shift-DR state and shift in the TDI value. Compare all 
 * bits of the expected value against the TDO value that is shifted out. At the 
 * end of the operation, go to the state specified in the last XENDDR command.
 * No retries are performed.
 */
#define XSDRTDOE        0x11

/*! XSVF command code. Immediately set the TAP controller to Test-Logic-Reset (0) or Run-Test_idle (1). */
#define XSTATE          0x12

/*! XSVF command code. Set the XSIR end state to Run-Test-Idle (0) or Pause-IR (1). */
#define XENDIR          0x13

/*! XSVF command code. Set the XSDR/XSDRTDO end state to Run-Test-Idle (0) or Pause-DR (1). */
#define XENDDR          0x14

/*! XSVF command code. Go to the Shift-IR state and shift in the TDI value. XSIR2 uses two bytes for the TDI size. */
#define XSIR2           0x15

/*! XSVF command code. Embedded comment string follows. */
#define XCOMMENT        0x16

/*! XSVF command code. Not implemented. */
#define XWAIT           0x17

/*! Unknown XSVF command code, indicates an error. */
#define XUNKNOWN        0x18

/*@}*/


#endif
